/*
 * FileName：WebsiteServiceIntroductionServiceImpl.java 
 * <p>
 * Copyright (c) 2017-2020 <a href="https://www.smartwx.info">hermit(1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.wx.wxcms.service.impl;

import javax.annotation.Resource;

import com.smart.common.util.AjaxResult;
import com.smart.common.util.StringUtil;
import com.smart.common.util.Util;
import com.smart.wx.wxcms.dao.WebsiteServiceIntroductionMapper;
import com.smart.wx.wxcms.entity.WebsiteServiceIntroduction;
import com.smart.wx.wxcms.service.WebsiteServiceIntroductionService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;


/**
 * 网站模板-----服务介绍
 *
 * @author hermit
 * @version 2.0
 * @date 2018-07-12 23:13:44
 */
@Service
public class WebsiteServiceIntroductionServiceImpl implements WebsiteServiceIntroductionService {

	@Resource
	private WebsiteServiceIntroductionMapper websiteServiceIntroductionMapper;

    @Override
    public WebsiteServiceIntroduction queryObject(WebsiteServiceIntroduction websiteServiceIntroduction) throws Exception {
        return websiteServiceIntroductionMapper.queryObject(websiteServiceIntroduction);
    }
	
	@Override
	public List<WebsiteServiceIntroduction> queryList(WebsiteServiceIntroduction websiteServiceIntroduction) throws Exception {
		return websiteServiceIntroductionMapper.queryList(websiteServiceIntroduction);
	}

    @Override
    public List<WebsiteServiceIntroduction> queryListByPage(WebsiteServiceIntroduction websiteServiceIntroduction) throws Exception {
        return websiteServiceIntroductionMapper.queryListByPage(websiteServiceIntroduction);
    }

	@Override
	public Integer queryCount(WebsiteServiceIntroduction websiteServiceIntroduction) throws Exception {
        Integer ct = websiteServiceIntroductionMapper.queryCount(websiteServiceIntroduction);
        return ct == null ? 0 : ct;
	}
	
	@Override
	public Integer insert(WebsiteServiceIntroduction websiteServiceIntroduction) throws Exception {
        return websiteServiceIntroductionMapper.insert(websiteServiceIntroduction);
	}
	
	@Override
	public Integer update(WebsiteServiceIntroduction websiteServiceIntroduction) throws Exception {
        return websiteServiceIntroductionMapper.update(websiteServiceIntroduction);
	}
	
	@Override
	public Integer delete(WebsiteServiceIntroduction websiteServiceIntroduction) throws Exception {
		String introductionId = websiteServiceIntroduction.getId();
		if(StringUtil.isNotBlank(introductionId)){
			this.websiteServiceIntroductionMapper.deleteBatch(Arrays.asList(introductionId.split(",")));
		}
		return 1;
	}

	@Override
	public Integer deleteBatch(List<String> ids) throws Exception {
		return websiteServiceIntroductionMapper.deleteBatch(ids);
	}

	@Override
	public AjaxResult saveOrUpdate(WebsiteServiceIntroduction introduction) throws Exception {

		String introductionId = introduction.getId();
		if (StringUtil.isNotBlank(introductionId)) { // 修改
			introduction.setUpdateTime(new Date());
			this.websiteServiceIntroductionMapper.update(introduction);
		}else{ // 新增
			introduction.setId(Util.getUUID());
			introduction.setCreateTime(new Date());
			introduction.setUpdateTime(new Date());
			this.websiteServiceIntroductionMapper.insert(introduction);
		}
		return AjaxResult.saveSuccess();
	}
}
